package ${package} ;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.SqlMapClientOperations;

import ${domain};
import ${dao};

/**
 * 
 * @author ${author}
 * @version ${version}
 *
 */

public class ${className}DaoImpl implements  ${className}Dao{

	private final Logger logger = LoggerFactory.getLogger(${className}DaoImpl.class);

	
	public Long add${className}(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before add${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		Long id = (Long) sqlMapClientOperations.insert("${className}.add${className}", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After add${className}(${className}), return [" + id + "]");
		}
		return id;
	}
	
	public void del${className}(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before del${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		sqlMapClientOperations.update("${className}.del${className}", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After del${className}(${className}), return [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
	}
	
	public void update${className}(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before update${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		sqlMapClientOperations.update("${className}.update${className}", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After update${className}(${className}), return [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}		
	}
	
	public ${className} find${className}(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before list${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		<@lowerFirstChar>${className}</@lowerFirstChar> = (${className}) sqlMapClientOperations.queryForObject("${className}.find${className}", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After list${className}(${className}), return [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		return <@lowerFirstChar>${className}</@lowerFirstChar>;
	}
	
	@SuppressWarnings("unchecked")
	public List<${className}> list${className}(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before list${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		List<${className}> list = sqlMapClientOperations.queryForList("${className}.list${className}", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After list${className}(${className}), return [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		return list;
	}
	
	public Integer list${className}Count(${className} <@lowerFirstChar>${className}</@lowerFirstChar>) 
			throws DataAccessException {
		if (logger.isDebugEnabled()) {
			logger.debug("Before listCount${className}(${className}), paramters is [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		Integer count = (Integer) sqlMapClientOperations.queryForObject("${className}.list${className}Count", <@lowerFirstChar>${className}</@lowerFirstChar> );
		if (logger.isDebugEnabled()) {
			logger.debug("After listCount${className}(${className}), return [" + <@lowerFirstChar>${className}</@lowerFirstChar> + "]");
		}
		return count;		
	}
	
	private SqlMapClientOperations sqlMapClientOperations;
	
	public void setSqlMapClientOperations(SqlMapClientOperations sqlMapClientOperations) {
		this.sqlMapClientOperations = sqlMapClientOperations;
	}

} 
